package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.CommentOfVideo;
import cn.wolfcode.trip.base.domain.Video;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.query.VideoQueryObject;
import cn.wolfcode.trip.base.service.IVideoService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/videos")
public class VideoController {
    @Autowired
    private IVideoService videoService;
    @PostMapping
    public Object addVideo(Video video){
        videoService.save(video);
        return new JSONResult();
    }
    @GetMapping("/{id}")
    public Object selectById(@PathVariable Long id){
        videoService.addNum(id);
        Video video = videoService.selectById(id);
        return video;
    }
    @GetMapping
    public Object ListAll(VideoQueryObject qo){
        qo.setOrderBy("v.time desc");
        qo.setState(1);
        PageInfo pageInfo = videoService.query(qo);
        return pageInfo;
    }
    @PostMapping("/{id}/comment")
    public Object postComment(CommentOfVideo comment){
        videoService.saveComment(comment);
        return new JSONResult();
    }
    @GetMapping("/{id}/comment")
    public Object getComment(CommentQueryObject qo){
        PageInfo pageInfo = videoService.queryComment(qo);
        return pageInfo;
    }
}
